package com.example.base.mvvm

import androidx.lifecycle.ViewModel
import com.example.base.net.ApiServer
import com.example.base.net.RetrofitUtils
import com.google.gson.Gson
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody

open class BaseViewModel:ViewModel() {
    //实例化apiServer
    val apiServer = RetrofitUtils.getRetrofit().create(ApiServer::class.java)
    //封装方法 ---将map转成body
    fun mapToBody(map:MutableMap<String,Any>):RequestBody{
        val json = Gson().toJson(map)
        val body = RequestBody.create("application/json;charset=utf-8".toMediaType(),json)
        return body
    }
}